package com.bayihouse.controller;

import com.bayihouse.model.excel.publicClass.father.BaseEntity;
import com.bayihouse.model.request.baseEntity.BaseEntityQueryRequest;
import com.bayihouse.model.vo.BaseEntityVO;
import com.bayihouse.service.BaseEntityService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/base")
public class BaseEntityController {

    private static final String[] dataBases = {"netobject", "community", "house", "unit", "room", "occupant"};

    @Resource
    private BaseEntityService baseEntityService;

    @RequestMapping("/get")
    public List<BaseEntityVO> getObject(@RequestBody BaseEntityQueryRequest baseEntityQueryRequest) {
        List<BaseEntity> objectList = baseEntityService.getObject(dataBases[baseEntityQueryRequest.getRank()], baseEntityQueryRequest.getFatherId());
        List<BaseEntityVO> objectListVO = BaseEntityVO.objToVOList(objectList, baseEntityQueryRequest.getRank());
        return objectListVO;
    }
}
